home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performRebuildSurfaceSet.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.0 KB  |  211 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Mar 14, 1997
  22. //  Author:         laf 
  23. //
  24. //  Description:
  25. //      This script runs rebuild surface on the selection list.
  26. //
  27.  
  28.  
  29. global proc performRebuildSurfaceSet( int $doHistory, int $replaceOriginal,
  30.                                       int $rebuildType, float $globalTol,
  31.                                       int $srfNumSpansU, int $srfNumSpansV,
  32.                                       int $srfDegreeU, int $srfDegreeV,
  33.                                       int $endKnots,
  34.                                       int $keepParmRange, int $keepCornerPts,
  35.                                       int $keepControlPoints, int $direction,
  36.                                       int $srfUseGlobalTol, float $srfLocalTol,
  37.                                       int $polys )
  38. {
  39.     // Get a list of each type of acceptable object type - 
  40.     // surfaces, and surfaces-on-surface.
  41.     //
  42.     global int $gSelectNurbsSurfacesBit;
  43.     global int $gSelectSubdivSurface;
  44.     global int $gSelectIsoparmsBit;
  45.     global int $gSelectMeshesBit;
  46.     string $surfaceList[] =`filterExpand -ex true -sm $gSelectNurbsSurfacesBit`;
  47.     string $isoparmList[] = `filterExpand -ex true -sm $gSelectIsoparmsBit`;
  48.  
  49.     if( $rebuildType == 2 ) {
  50.         if( (size($surfaceList) + size($isoparmList)) < 2 ) {
  51.             error( "Select at least two NURBS surfaces/isoparms to " +
  52.                    "rebuild with match knots option.") ;
  53.             return;
  54.         }
  55.     }
  56.     else {
  57.         if( (size($surfaceList) + size($isoparmList)) < 1 ) {
  58.             error( "Nothing was selected to rebuild.  You must select " +
  59.                    "NURBS surfaces or surface isoparms.");
  60.             return;
  61.         }
  62.     }
  63.  
  64.     // Put together the command to execute
  65.     //
  66.     $cmd = "rebuildSurface" + " -ch " + $doHistory + 
  67.            " -rpo " + $replaceOriginal+
  68.            " -rt " + $rebuildType + 
  69.            " -end " + $endKnots +
  70.            " -kr " + $keepParmRange +
  71.            " -kcp " + $keepControlPoints +
  72.            " -kc " + $keepCornerPts;
  73.  
  74.     $cmd += " -su " + $srfNumSpansU + " -du " + $srfDegreeU;
  75.     $cmd += " -sv " + $srfNumSpansV + " -dv " + $srfDegreeV;
  76.  
  77.     if( $srfUseGlobalTol == 0 ) {    // Use globl tolerance vs. local tolerance
  78.         $cmd += " -tol " + $srfLocalTol;
  79.     } else {
  80.         $cmd += " -tol " + $globalTol;
  81.     }
  82.     if( $polys ) {
  83.         $cmd += " -po " + $polys;
  84.     }
  85.     $cmd += " ";
  86.  
  87.     // Execute the command on all surfaces
  88.     //
  89.     int $i;
  90.     string $isoCmd; $isoCmd = $cmd;
  91.     $cmd = $cmd + " -dir " + $direction ;
  92.     string $surfaceResults[] ;
  93.     if( $rebuildType == 2 ) {
  94.         int $l = size($surfaceList) ;
  95.         if( $l > 2 ) {
  96.             warning( "Rebuilding all but the last surface to match knots " +
  97.                      "of the last surface in the selection list" );
  98.         }    
  99.         if( $l >= 2 ) {
  100.             int $nitems = 2 ;
  101.             $cmd = appendToCmdPlaceHoldersForSelectionItems( $cmd, $nitems ) ;
  102.             string $srfPair[2] ;
  103.             for( $i=0; $i<($l-1); $i+=1 ) {
  104.                 $srfPair[0] = $surfaceList[$i] ;
  105.                 $srfPair[1] = $surfaceList[$l-1] ;
  106.                 string $oneRes[] = executeCmdOnItems($cmd,$srfPair);
  107.                 appendStringArray( $surfaceResults, $oneRes, size($oneRes) );
  108.             }
  109.         }
  110.     } else {
  111.         $surfaceCmd = $cmd + " %s;";
  112.         $surfaceResults = executeForEachObject( $surfaceList, $surfaceCmd );
  113.     }
  114.  
  115.     // Processing isoparms is a little more involved.  Use groupObjectsByName().
  116.     // This chunk of code groups the isoparms from the selection list
  117.     // and uses them to guess a rebuild direction.  If an isoparm is
  118.     // selected in both directions on the same surface, then this
  119.     // will figure out that the user wants to rebuild in BOTH directions.
  120.     // Even if the user has selected >1 U isoparms on the same surface, 
  121.     // this will only call the rebuild command ONCE.
  122.     //
  123.     string $isoparmResults[];
  124.     string $isoparms[] = groupObjectsByName( $isoparmList, "." );
  125.     int $numIsoStrs = size($isoparms);
  126.     for( $i = 0; $i < $numIsoStrs; $i ++ ) {
  127.  
  128.         string $rebuildCmd;
  129.         string $results[];
  130.         string $objectName[];
  131.         string $names[];
  132.  
  133.         tokenize $isoparms[$i] " " $objectName;
  134.         $names = groupObjectsByName( $objectName, "\\[" );
  135.  
  136.         if( size($names) > 1 ) {
  137.             tokenize $isoparms[$i] "\\." $objectName;
  138.             $rebuildCmd = $isoCmd + " -dir 2 " + $objectName[0];
  139.         }
  140.         else {
  141.             string $foundU = `match "\\.u\\[" $names[0]`;
  142.             if( size($foundU) > 0 ) {
  143.                 tokenize $isoparms[$i] "\\." $objectName;
  144.                 $rebuildCmd = $isoCmd + " -dir 1 " + $objectName[0];
  145.             }
  146.             else {
  147.                 string $foundV = `match "\\.v\\[" $names[0]`;
  148.                 if( size($foundV) > 0 ) {
  149.                     tokenize $isoparms[$i] "\\." $objectName;
  150.                     $rebuildCmd = $isoCmd + " -dir 0 " + $objectName[0];
  151.                 }
  152.             }
  153.         }
  154.  
  155.         if( catch( $results = evalEcho( $rebuildCmd )) ) {
  156.             warning( "Problem executing rebuild command: " + $rebuildCmd);
  157.         }
  158.         else {
  159.             int $j;
  160.             int $numResults = size( $results );
  161.             int $numIsoResults = size( $isoparmResults );
  162.             for( $j = 0; $j < $numResults; $j ++, $numIsoResults ++ ) {
  163.                 $isoparmResults[$numIsoResults] = $results[$j];
  164.             }
  165.         }
  166.     }
  167.  
  168.     if( (size($surfaceResults)+size($isoparmResults)) == 0 ) {    
  169.         int $l = size($surfaceList) ;
  170.         if( $rebuildType == 2 ) {
  171.             if( $l < 2 ) {
  172.                 error( "Select at least two NURBS surfaces to " +
  173.                        "rebuild with match knots option.") ;
  174.             }
  175.             else {
  176.                 error("Rebuild surface failed on the current valid selection.");
  177.             }
  178.         }
  179.         else if( 0 == $l ) {
  180.             error( "Nothing was selected to rebuild.  You must select " +
  181.                    "NURBS surfaces or surface isoparms.");
  182.         }
  183.         else {
  184.             error( "Rebuild surface failed on the current valid selection." );
  185.         }
  186.     } else {
  187.         // Select all the results with one select command.  Note that only
  188.         // resulting surfaces and surfaces are selected, not dependency nodes.
  189.         //
  190.         string $selectString;
  191.         $selectString = "select ";
  192.         int $i;
  193.         $surfaceResults = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectSubdivSurface -sm $gSelectMeshesBit $surfaceResults`;
  194.         int $numSurfaces = size($surfaceResults);
  195.         for( $i = 0; $i < $numSurfaces; $i ++ ) {
  196.             $selectString += $surfaceResults[$i];
  197.             $selectString += " ";
  198.         }
  199.         $isoparmResults = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectSubdivSurface -sm $gSelectMeshesBit $isoparmResults`;
  200.         int $numSurfaces = size($isoparmResults);
  201.         for( $i = 0; $i < $numSurfaces; $i ++ ) {
  202.             $selectString += $isoparmResults[$i];
  203.             $selectString += " ";
  204.         }
  205.         $selectString += ";";
  206.         select -cl;
  207.         eval($selectString);
  208.     }
  209. }
  210.  
  211.